<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>退货单据查询</title>
<link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
<link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.3.3/themes/icon.css"></link>
<script type="text/javascript" src="../static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jqsetup.js"></script>
<script type="text/javascript" src="../static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript" src="../static/js/date.js"></script>
<script type="text/javascript">


	
	function formatSupplier(val,row){
		return val.name;
	}
	
	function formatAmountPayable(val,row){
		return "￥"+val;
	}
	
	$(document).ready(function(){

		

		$("#s_bReturnDate").datebox("setValue",genLastMonthDayStr()); // 设置上个月日期
		$("#s_eReturnDate").datebox("setValue",genTodayStr()); // 设置当前日期
		
		
		$('#dg').datagrid({
			onClickRow: function(index,row){
				$("#dg2").datagrid({
					url:'/admin/returnList/listGoods',
					queryParams:{
						returnListId:row.id
					}
				});
			}
		});
		
	});
	
	function formatTotal(val,row){
		return "￥"+val.toFixed(2);
	}
	
	function formatPrice(val,row){
		return "￥"+val;
	}
	
	
	function searchReturn(){
		$('#dg2').datagrid('loadData', { total: 0, rows: [] });  
		var supplierId;
		if(isNaN($("#s_supplier").combobox("getValue"))){
			supplierId="";
		}else{
			supplierId=$("#s_supplier").combobox("getValue");
		}
		$("#dg").datagrid({
			url:'/admin/returnList/list',
			queryParams:{
				returnNumber:$("#s_returnNumber").val(),
				'supplier.id':supplierId,
				state:$("#s_state").combobox("getValue"),
				bReturnDate:$("#s_bReturnDate").datebox("getValue"),
				eReturnDate:$("#s_eReturnDate").datebox("getValue")
			}
		});
	}
	
	function deleteReturn(){
		var selectedRows=$("#dg").datagrid("getSelections");
		if(selectedRows.length!=1){
			 $.messager.alert("系统提示","请选择要删除的退货单！");
			 return;
		 }
		 var id=selectedRows[0].id;
		 $.messager.confirm("系统提示","<font color=red>删除退货单后将无法恢复，是否删除？</font>",function(r){
				if(r){
					$.post("/admin/returnList/delete",{id:id},function(result){
						if(result.success){
							 $("#dg").datagrid("reload");
							 $("#dg2").datagrid("reload");
						}else{
							$.messager.alert("系统提示",result.errorInfo);
						}
					},"json");
				} 
	    });
	}
	
	function formatUser(val,row){
		return val.trueName;
	}

</script>
</head>
<body class="easyui-layout" style="margin: 1px">
<div region="north" style="height: 350px;">
	<table id="dg" title="退货单据查询" class="easyui-datagrid" fit=true
	   fitColumns="true"  rownumbers="true" singleSelect="true"
	    toolbar="#tb" >
	   <thead>
	   	<tr>    
	   	    <th field="id" width="30" align="center" hidden="true">退货单ID</th>
	   		<th field="returnNumber" width="30" align="center">退货单号</th>
	   		<th field="returnDate" width="20" align="center">退货日期</th>
	   		<th field="supplier" width="50" align="center" formatter="formatSupplier">供应商</th>
	   		<th field="amountPayable" width="15" align="right" formatter="formatAmountPayable">退货金额</th>
	   		<th field="user" width="20" align="center" formatter="formatUser">操作员</th>
	   		<th field="remarks" width="100" align="center">备注</th>
	   	</tr>
	   </thead>
	 </table>
	 
	 <div id="tb">
	 	<div style="padding-bottom: 5px">
	 		<fieldset style="border-color: #E7F0FF">
	 			<legend>查询设置</legend>
	 	    &nbsp;单据号：&nbsp;
	 		<input type="text" id="s_returnNumber" size="15" onkeydown="if(event.keyCode==13) searchReturn()"/>
	 		&nbsp;&nbsp;&nbsp;供应商：&nbsp;
	 		<select class="easyui-combobox"  id="s_supplier"  style="width: 200px;"  data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'/admin/supplier/comboList'"></select>
	 		&nbsp;&nbsp;&nbsp;是否付款：
	 		<select class="easyui-combobox"  id="s_state"  style="width: 100px;" editable="false" panelHeight="auto">
	 		    <option value="">全部</option>
				<option value="1">已付</option>
                <option value="2">未付</option>	
		   </select>
	 		&nbsp;&nbsp;&nbsp;日期：&nbsp;
	 		<input id="s_bReturnDate" class="easyui-datebox" editable=false  style="width:100px">
	 	&nbsp;&nbsp;-&nbsp;&nbsp;
	 		<input id="s_eReturnDate" class="easyui-datebox" editable=false  style="width:100px">
	 		&nbsp;&nbsp;<a href="javascript:searchReturn()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
	 		&nbsp;&nbsp;<a href="javascript:deleteReturn()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
	 		</fieldset>
	 	</div>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
	 </div>
</div>
<div region="center" style="margin-top: 5px;">
	 <table id="dg2"  class="easyui-datagrid" fit=true
	   fitColumns="true"  rownumbers="true" singleSelect="true"
	      >
	   <thead>
	   	<tr>
	   		<th field="code" width="30" align="center">商品编码</th>
	   		<th field="name" width="150" align="center">商品名称</th>
	   		<th field="model" width="50" align="center">商品型号</th>
	   		<th field="price" width="50" align="center" formatter="formatPrice">单价</th>
	   		<th field="num" width="50" align="center" >数量</th>
	   		<th field="unit" width="50" align="center" >单位</th>
	   		<th field="total" width="50" align="center" formatter="formatTotal">总金额</th>
	   	</tr>
	   </thead>
	 </table>
</div>
</body>
</html>